<template>
  <div class="hello">
    <input v-model="text"/>
  </div>
</template>

<script>
import { customRef } from 'vue'
const useDebouncedRef = function (value, delay=20){
  let timeout
  return customRef((track, trigger)=>{
    return {
      get(){
        track()
        return value
      },
      set(newValue){
        clearTimeout(timeout)
        timeout=setTimeout(()=>{
          value = newValue;
          trigger()
        }, delay)
      }
    }
  })
}
export default {
  name: 'HelloWorld',
  props: {
    msg: String
  },
  data(){
    return {
      text: useDebouncedRef("hello")
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h3 {
  margin: 40px 0 0;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
